package com.lagou.demo03.servlet;

import com.lagou.demo03.model.Student;
import com.lagou.demo03.service.ClassStudentQueryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ClassStudentQueryServlet",urlPatterns = "/classStudentQuery")
public class ClassStudentQueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取请求中的班级信息
        String queryClassName = request.getParameter("queryClassStudent");
        request.setAttribute("queryClassName",queryClassName);
        System.out.println("servlet:"+queryClassName);
        ClassStudentQueryService classStudentQueryService = new ClassStudentQueryService();
        List<Student> queryClassStudentList = classStudentQueryService.classStudnetQueryService(queryClassName);
        request.setAttribute("queryClassList", queryClassStudentList);
        request.getRequestDispatcher("queryStudent.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
